<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
    // 在js中创建对象的方式有哪些？
    // 第一种  字面量创建对象
    let obj = {}
    obj.name = '张三'
    obj.age = 18
    obj.sing = function(){
        console.log('sing');
    }
   console.log(obj);
//    第二种  构造函数创建对象
function Star(){
  
   this.name = '李四',
   this.sex = '男'
   this.eat = function(){
    console.log('eat');
   }
   console.log(this);//this指向实例化出来的对象
}

let star = new Star()
console.log(star);

// 第三种  es6里面的class类
class Person{
    constructor(name,age){
        this.name = name
        this.age = age
        this.sing = function(){
            console.log('sing');
        }
        console.log(this);//this指向实例化出来的对象
    }
}

let p = new Person('刘德华',18)
console.log(p);

// 第四种 工厂模式

function fun(name,age){
    let o = new Object
    o.name = name
    o.age = age
    return o
}
console.log(fun('张学友0',40));
console.log(fun('张学友1',40));
console.log(fun('张学友2',40));
console.log(fun('张学友3',40));





</script>
</html>